package io.renren.modules.evaluate.util;

import java.math.BigDecimal;

public class AdcTest {
    public static void main(String[] args) {
        double [] arrayA= {0.2,0.65,0.3};
        double [] arrayC= {0.2,0.75,0.3};
        double[][] arrayD = {{0.2,0.65,0.3},{0.2,0.95,0.3},{0.2,0.75,0.3}};
        double v= valueAdc(arrayA,arrayD,arrayC);
        BigDecimal b   =   new   BigDecimal(v);//保留4位小数
        v =   b.setScale(4,   BigDecimal.ROUND_HALF_UP).doubleValue();
        System.out.println(v);
    }
    public static double valueAdc(double[] arrayA, double[][] arrayD, double[]arrayC) {
        int n= arrayA.length;
        double[] Temp1= new double[n];
        double[] Temp2= new double[n];
        double[] TempResult= new double[n];//存放临时的计算结果
        double value = 0;
        for (int i = 0; i<arrayA.length; i++)
        {
            for (int j = 0; j<arrayD[i].length; j++)
            {
                Temp1[j]= arrayA[j] * arrayD[i][j];
            }
            //累加求和
            Temp2[i]=sumValue(Temp1);
        }
        for (int i = 0; i<Temp2.length; i++)
        {
            TempResult [i]  = Temp2[i] * arrayC[i];
        }
        value = sumValue(TempResult);

        return value;
    }
    public static double sumValue(double[] data){
        double sum = 0;
        for(int i = 0; i < data.length; i++)
        {
            sum = sum + data[i];
        }
        return sum;

    }
}

